using Assets;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CubeControl : MonoBehaviour
{
    public List<Transform> child;
    float dis = 0;
    Vector3 startPos;
    // Start is called before the first frame update
    void Start()
    {
        startPos = transform.position;
        dis=Vector3.Distance(transform.position, child[0].transform.position);
        for(int i = 0; i < child.Count; i++)
        {
            if (i == 0)
            {
                child[i].gameObject.AddComponent<CubeBody>().Init(transform);
            }
            else
            {
                child[i].gameObject.AddComponent<CubeBody>().Init(child[i-1]);
            }
        }
    }
    // Update is called once per frame
    void Update()
    {

        //Debug.Log(Time.deltaTime);
        float h = Input.GetAxis("Horizontal");
        float v = Input.GetAxis("Vertical");
        if(h != 0 || v != 0)
        {

            transform.LookAt(transform.position+new Vector3(h,0,v));

        }
        Vector3 movement = transform.forward * 5f * Time.deltaTime;
        transform.position += movement;
        for (int i = 0; i < child.Count; i++)
        {
            child[i].GetComponent<CubeBody>().MyUpdate();
        }
    }
}
